app.service('goodsFileUploadService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.del=function($scope,item){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'upload/',
            data:{filefullPath:item.fileName},
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}])

app.service('goodsDetailPicturesService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.addGoodsImages=new Array();

    _this_.findByGoodsId=function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'chain/goods/images/goodsid/'+$scope.chainGoodsId,
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }


    _this_.add=function($scope){

        var GoodsImagesAddVOJson=new Array();
        for(var i=0;i<_this_.addGoodsImages.length;i++ ){
            var goodsImagesAddVO=new Object();

            goodsImagesAddVO.fileName=_this_.addGoodsImages[i].fileName;
            goodsImagesAddVO.type=_this_.addGoodsImages[i].type;
            goodsImagesAddVO.sort=_this_.addGoodsImages[i].sort;
            goodsImagesAddVO.chainGoodsId=$scope.chainGoodsId;

            GoodsImagesAddVOJson.push(goodsImagesAddVO);
        }

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'chain/goods/images',
            data:{goodsImagesAddVOJson:JSON.stringify(GoodsImagesAddVOJson)}
        }).then(function(result){
            _this_.addGoodsImages.splice(0,_this_.addGoodsImages.length);
            GoodsImagesAddVOJson.splice(0,GoodsImagesAddVOJson.length);
            deferred.resolve(result);
        });

        return deferred.promise;
    }


    _this_.deleteGoodsImage=function($scope,id){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'chain/goods/images',
            data:{id:id},
            method:'DELETE'
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }

}])